home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2003 March / DPPCPRO0303.ISO / Components / Microsoft ASP / _SETUP.1 / ASPWizard.jar / asp / wizard / WizardModelDbList3.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-20  |  14.2 KB  |  353 lines

  1. package asp.wizard;
  2.  
  3. import asp.netobjects.nfx.util.ExceptionHandler;
  4. import asp.netobjects.nfx.util.ExternalError;
  5. import asp.netobjects.nfx.util.InternalError;
  6. import asp.netobjects.nfx.wizard.Wizard;
  7. import asp.netobjects.nfx.wizard.WizardPage;
  8. import asp.netobjects.nfx.wizard.WizardPageView;
  9. import asp.util.ResourceUtil;
  10. import asp.wizard.def.DefAbstract;
  11. import asp.wizard.def.DefCollection;
  12. import asp.wizard.def.DefConnection;
  13. import asp.wizard.def.DefList;
  14. import asp.wizard.def.DefPage;
  15. import asp.wizard.def.DefQuery;
  16. import asp.wizard.util.UiUtil;
  17. import com.sun.java.swing.DefaultListModel;
  18. import com.sun.java.swing.ImageIcon;
  19. import com.sun.java.swing.table.DefaultTableModel;
  20. import com.sun.java.swing.table.TableModel;
  21. import java.lang.reflect.Array;
  22. import java.sql.Connection;
  23. import java.sql.ResultSet;
  24. import java.text.MessageFormat;
  25. import java.util.Vector;
  26.  
  27. public class WizardModelDbList3 extends WizardModelAbstract {
  28.    private static final String ERR_TOOMANY_KEYFIELDS = "msg.error.toomanykeyfields";
  29.    private static final String ERR_MISSING_VALUE_ON_LINE = "msg.error.missingvalueonline";
  30.    private static final String OPT_KEYFIELD_TYPE = "option.kfldtype";
  31.    private static final int MSDBLIST_MAX_KEYFIELDS = 10;
  32.    private DefList _defList;
  33.    private int _linkOption = 1001;
  34.    // $FF: synthetic field
  35.    static Class class$java$lang$String;
  36.    // $FF: synthetic field
  37.    static Class class$asp$wizard$WVPanelDbListLink;
  38.    // $FF: synthetic field
  39.    static Class class$asp$nfx$MSDBList$MSDBList;
  40.    // $FF: synthetic field
  41.    static Class class$java$lang$Object;
  42.    // $FF: synthetic field
  43.    static Class class$asp$wizard$WizardModelDbConnection;
  44.    // $FF: synthetic field
  45.    static Class class$asp$wizard$WizardModelDbQuery;
  46.    // $FF: synthetic field
  47.    static Class class$asp$wizard$WizardModelDbDetail;
  48.  
  49.    public void commit() throws InternalError, ExternalError {
  50.       WizardViewDbList3 view = (WizardViewDbList3)((WizardPage)this).getView();
  51.       this._defList.setHyperlinkField(view.getHyperlinkField());
  52.       this._linkOption = view.getLinkOption();
  53.       TableModel tm = view.getFieldSpecTable().getModel();
  54.  
  55.       for(int i = 0; i < tm.getRowCount(); ++i) {
  56.          if (tm.getValueAt(i, 2).toString().compareTo("") == 0) {
  57.             tm.setValueAt(tm.getValueAt(i, 0), i, 2);
  58.          }
  59.       }
  60.  
  61.       this._defList.setKeyFieldNames((String[])UiUtil.getColumnArrayFromTableModel(0, tm, class$java$lang$String != null ? class$java$lang$String : (class$java$lang$String = class$("java.lang.String"))));
  62.       Vector dataTypes = this.getDataTypes();
  63.       this._defList.setKeyFieldDataTypes(getColumnArrayFromTableModelTranslate(1, tm, Integer.TYPE, dataTypes));
  64.       this._defList.setKeyFieldLabels((String[])UiUtil.getColumnArrayFromTableModel(2, tm, class$java$lang$String != null ? class$java$lang$String : (class$java$lang$String = class$("java.lang.String"))));
  65.    }
  66.  
  67.    public void loadValues() {
  68.       WizardViewDbList3 view = (WizardViewDbList3)((WizardPage)this).getView();
  69.       DefaultTableModel tm = (DefaultTableModel)view.getFieldSpecTable().getModel();
  70.       view.setLinkOption(this._linkOption);
  71.       view.updateFieldSpecTableColumnsVisibility();
  72.       tm.setNumRows(0);
  73.       UiUtil.setTableModelFromColumnArray(0, tm, this._defList.getKeyFieldNames());
  74.       UiUtil.setTableModelFromColumnArray(2, tm, this._defList.getKeyFieldLabels());
  75.       Vector dataTypes = this.getDataTypes();
  76.       setTableModelFromColumnArrayTranslate(1, tm, this._defList.getKeyFieldDataTypes(), dataTypes);
  77.       view.setHyperlinkField(this._defList.getHyperlinkField());
  78.    }
  79.  
  80.    public void loadView() {
  81.       WizardManager wm = ((WizardModelAbstract)this).getWizardManager();
  82.       this._defList = wm.getDefList(this);
  83.       WizardViewDbList3 view = (WizardViewDbList3)((WizardPage)this).getView();
  84.       view.setDataType(this.getDataTypes());
  85.       view.setHLFieldList(this.getListFields());
  86.       view.setLinkOption(this._linkOption);
  87.       DefaultListModel lm = (DefaultListModel)view.getFieldList().getModel();
  88.       DefQuery defQuery = this.getDefQuery();
  89.       if (defQuery != null) {
  90.          lm.setSize(0);
  91.  
  92.          try {
  93.             WizDbManager.getFields(defQuery, false, lm);
  94.          } catch (EWizDbManager e) {
  95.             AspWizardExceptionHandler.showMessage(0, ((Throwable)e).getMessage());
  96.          }
  97.       }
  98.  
  99.       this.loadValues();
  100.       DefaultTableModel tm = (DefaultTableModel)view.getFieldSpecTable().getModel();
  101.       UiUtil.validateTableAgainstList(tm, lm, 0);
  102.    }
  103.  
  104.    public void validate() throws InternalError, ExternalError {
  105.       super.validate();
  106.       WizardViewDbList3 view = (WizardViewDbList3)((WizardPage)this).getView();
  107.       DefaultTableModel KFCollection = view.getKeyFields();
  108.       if (KFCollection.getRowCount() > 10) {
  109.          String msg = ResourceUtil.getResourceString("asp.wizard.res", class$asp$wizard$WVPanelDbListLink != null ? class$asp$wizard$WVPanelDbListLink : (class$asp$wizard$WVPanelDbListLink = class$("asp.wizard.WVPanelDbListLink")), "msg.error.toomanykeyfields");
  110.          Object[] args = new Object[]{new Integer(10)};
  111.          msg = MessageFormat.format(msg, args);
  112.          throw new EWizardModelExt(msg);
  113.       } else {
  114.          for(int i = 0; i < KFCollection.getRowCount(); ++i) {
  115.             if (KFCollection.getValueAt(i, 0).toString().length() == 0 || KFCollection.getValueAt(i, 1).toString().length() == 0) {
  116.                String err = ResourceUtil.getResourceString("asp.wizard.res", class$asp$wizard$WVPanelDbListLink != null ? class$asp$wizard$WVPanelDbListLink : (class$asp$wizard$WVPanelDbListLink = class$("asp.wizard.WVPanelDbListLink")), "msg.error.missingvalueonline");
  117.                Object[] args = new Object[]{new Integer(i + 1)};
  118.                String str = MessageFormat.format(err, args);
  119.                throw new ExternalError(str);
  120.             }
  121.          }
  122.  
  123.       }
  124.    }
  125.  
  126.    private DefQuery getDefQuery() {
  127.       DefQuery result = null;
  128.       WizardManager wm = ((WizardModelAbstract)this).getWizardManager();
  129.       if (wm != null) {
  130.          result = wm.getDefQuery(this);
  131.       } else {
  132.          System.err.println("WizardManager not found");
  133.       }
  134.  
  135.       return result;
  136.    }
  137.  
  138.    public Vector getDataTypes() {
  139.       String test = ResourceUtil.getResourceString("asp.nfx.res", class$asp$nfx$MSDBList$MSDBList != null ? class$asp$nfx$MSDBList$MSDBList : (class$asp$nfx$MSDBList$MSDBList = class$("asp.nfx.MSDBList.MSDBList")), "option.kfldtype");
  140.       Vector result = UiUtil.strToVector(test);
  141.       return result;
  142.    }
  143.  
  144.    protected String getQueryDataType(String fieldName) {
  145.       String result = "";
  146.       ResultSet rs = null;
  147.       DefQuery defQuery = this.getDefQuery();
  148.       if (defQuery != null) {
  149.          int DBType = -1;
  150.  
  151.          try {
  152.             DBType = WizDbManager.getDBTypes(defQuery, fieldName);
  153.          } catch (EWizDbManager e) {
  154.             AspWizardExceptionHandler.showMessage(0, ((Throwable)e).getMessage());
  155.          }
  156.  
  157.          String reserveWord = WizDbManager.getDataTypeName(DBType);
  158.          Vector internalDataTypes = WizDbManager.getInternalDataTypes();
  159.          Vector dataTypes = this.getDataTypes();
  160.          result = dataTypes.elementAt(internalDataTypes.indexOf(reserveWord)).toString();
  161.       }
  162.  
  163.       return result;
  164.    }
  165.  
  166.    protected String[] getListFields() {
  167.       WizardManager wm = ((WizardModelAbstract)this).getWizardManager();
  168.       DefList result = wm.getDefList(this);
  169.       return result.getFieldNames();
  170.    }
  171.  
  172.    public static void setTableModelFromColumnArrayTranslate(int colIndex, DefaultTableModel tableModel, int[] array, Vector lkpVector) {
  173.       if (tableModel != null && array != null) {
  174.          int colCount = tableModel.getColumnCount();
  175.          if (colIndex >= 0 && colIndex < colCount) {
  176.             int rowCount = Array.getLength(array);
  177.             tableModel.setNumRows(rowCount);
  178.  
  179.             for(int r = 0; r < rowCount; ++r) {
  180.                tableModel.setValueAt(lkpVector.elementAt(array[r]), r, colIndex);
  181.             }
  182.          }
  183.       }
  184.  
  185.    }
  186.  
  187.    public static int[] getColumnArrayFromTableModelTranslate(int colIndex, TableModel tableModel, Class columnClass, Vector lkpVector) {
  188.       int[] result = null;
  189.       if (columnClass == null) {
  190.          columnClass = class$java$lang$Object != null ? class$java$lang$Object : (class$java$lang$Object = class$("java.lang.Object"));
  191.       }
  192.  
  193.       if (tableModel != null && colIndex >= 0 && colIndex < tableModel.getColumnCount()) {
  194.          int rowCount = tableModel.getRowCount();
  195.          if (rowCount > 0) {
  196.             int[] aColumn = null;
  197.  
  198.             try {
  199.                aColumn = (int[])Array.newInstance(columnClass, rowCount);
  200.             } catch (Exception e) {
  201.                System.err.println("getColumnArrayFromTableModelTranslate(): " + ((Throwable)e).getMessage());
  202.             }
  203.  
  204.             if (aColumn != null) {
  205.                for(int r = 0; r < rowCount; ++r) {
  206.                   aColumn[r] = lkpVector.indexOf(tableModel.getValueAt(r, colIndex));
  207.                }
  208.  
  209.                result = aColumn;
  210.             }
  211.          }
  212.       }
  213.  
  214.       return result;
  215.    }
  216.  
  217.    public WizardModelDbList3() {
  218.    }
  219.  
  220.    public WizardModelDbList3(Wizard wizard, String bullet, String info, ImageIcon icon, ExceptionHandler handler) {
  221.       super(wizard, bullet, info, icon, handler);
  222.    }
  223.  
  224.    protected WizardPageView getViewSingleInstance() {
  225.       return WizardViewDbList3.getInstance();
  226.    }
  227.  
  228.    public WizardPage getNext(int nextSeqTemplateId) throws InternalError, ExternalError {
  229.       WizardPage next = super.getNext();
  230.       WizardManager wm = ((WizardModelAbstract)this).getWizardManager();
  231.       DefPage nextDefPage = null;
  232.       if (next != null && ((WizardModelAbstract)next).getTemplateId() != nextSeqTemplateId) {
  233.          nextDefPage = ((WizardModelAbstract)next).getDefPage();
  234.          next = wm.getSequenceHead(next);
  235.          wm.removeSequence(next);
  236.          next = null;
  237.          DefPage var12 = null;
  238.       } else if (next != null) {
  239.          WizardModelAbstract nextModel = (WizardModelAbstract)next;
  240.          if (nextModel.getTemplateId() == 1 || nextModel.getTemplateId() == 0) {
  241.             DefConnection currDefConn = wm.getDefConnection(this);
  242.             DefConnection nextDefConn = wm.getDefConnection(nextModel);
  243.             if (currDefConn != null && !currDefConn.equalConnectionTo(nextDefConn)) {
  244.                nextDefConn.setEqualConnectionTo(currDefConn);
  245.             }
  246.  
  247.             DefQuery nextDefQuery = wm.getDefQuery(nextModel);
  248.             if (nextDefQuery != null && nextDefQuery.getUsePreviousQuery() == 0) {
  249.                DefQuery currDefQuery = wm.getDefQuery(this);
  250.                if (!currDefQuery.equalSqlStatementTo(nextDefQuery)) {
  251.                   nextDefQuery.setEqualSqlStatementTo(currDefQuery);
  252.                   this.setupResultSetFor(nextDefQuery);
  253.                }
  254.             }
  255.          }
  256.       }
  257.  
  258.       if (next == null) {
  259.          if (nextSeqTemplateId != 2) {
  260.             nextDefPage = wm.createDefPage(this, nextSeqTemplateId);
  261.             ((WizardModelAbstract)this).getDefPage().addChildPage(nextDefPage);
  262.             wm.addSequence(this, this, nextDefPage, nextSeqTemplateId, (DefPage)null);
  263.             this.setupConnectionAndQueryModels(nextDefPage, nextSeqTemplateId);
  264.             wm.updateNextDefPageId(this, nextSeqTemplateId);
  265.          } else {
  266.             wm.addSequence(this, this, (DefPage)null, nextSeqTemplateId, (DefPage)null);
  267.          }
  268.  
  269.          next = super.getNext();
  270.       }
  271.  
  272.       return next;
  273.    }
  274.  
  275.    public WizardPage getNext() throws InternalError, ExternalError {
  276.       int nextSeqTemplateId = this.getSeqTemplateId();
  277.       return this.getNext(nextSeqTemplateId);
  278.    }
  279.  
  280.    public int getSeqTemplateId() {
  281.       WizardViewDbList3 wv = (WizardViewDbList3)((WizardPage)this).getView();
  282.       return wv.getSeqTemplateId();
  283.    }
  284.  
  285.    private void setupResultSetFor(DefQuery aDefQuery) throws InternalError {
  286.       try {
  287.          WizDbManager wdbm = WizDbManager.getInstance();
  288.          DefConnection defConnection = aDefQuery.getDefConnection();
  289.          Connection conn = wdbm.getConnection(defConnection.getDSNName(), defConnection.getUserName(), defConnection.getPassword());
  290.          ResultSet rs = wdbm.getResultSet(conn, aDefQuery.getSql());
  291.          aDefQuery.setResultSet(rs);
  292.       } catch (EWizDbManager e) {
  293.          throw new InternalError(((Throwable)e).getMessage());
  294.       }
  295.    }
  296.  
  297.    private void setupConnectionAndQueryModels(DefPage newDefPage, int nextSeqTemplateId) throws ExternalError, InternalError {
  298.       if (nextSeqTemplateId == 0 || nextSeqTemplateId == 1) {
  299.          WizardManager wizman = ((WizardModelAbstract)this).getWizardManager();
  300.          WizardModelAbstract model = null;
  301.          boolean needSetupNewQuery = nextSeqTemplateId == 1;
  302.          DefConnection defConnection = wizman.getDefConnection(this);
  303.          DefConnection newDefConnection = new DefConnection(defConnection);
  304.          ((DefAbstract)newDefConnection).setName(((DefCollection)newDefPage).getUniqueNameFor(newDefConnection));
  305.          ((DefCollection)newDefPage).addElement(newDefConnection);
  306.          DefQuery defQuery = null;
  307.          DefQuery newDefQuery = null;
  308.          if (needSetupNewQuery) {
  309.             defQuery = wizman.getDefQuery(this);
  310.             newDefQuery = new DefQuery(defQuery);
  311.             ((DefAbstract)newDefQuery).setName(((DefCollection)newDefPage).getUniqueNameFor(newDefQuery));
  312.             newDefQuery.setDefConnection(newDefConnection);
  313.             newDefQuery.setUsePreviousQuery(1);
  314.             this.setupResultSetFor(newDefQuery);
  315.             ((DefCollection)newDefPage).addElement(newDefQuery);
  316.             ((DefAbstract)newDefPage).setDefQuery(newDefQuery);
  317.          }
  318.  
  319.          switch (nextSeqTemplateId) {
  320.             case 0:
  321.                model = (WizardModelAbstract)wizman.getModelOfClassRightOf(class$asp$wizard$WizardModelDbConnection != null ? class$asp$wizard$WizardModelDbConnection : (class$asp$wizard$WizardModelDbConnection = class$("asp.wizard.WizardModelDbConnection")), this);
  322.                model.setSkip(true);
  323.                ((WizardModelDbConnection)model).setDefConnection(newDefConnection);
  324.                model = (WizardModelAbstract)wizman.getModelOfClassRightOf(class$asp$wizard$WizardModelDbQuery != null ? class$asp$wizard$WizardModelDbQuery : (class$asp$wizard$WizardModelDbQuery = class$("asp.wizard.WizardModelDbQuery")), this);
  325.                break;
  326.             case 1:
  327.                model = (WizardModelAbstract)wizman.getModelOfClassRightOf(class$asp$wizard$WizardModelDbConnection != null ? class$asp$wizard$WizardModelDbConnection : (class$asp$wizard$WizardModelDbConnection = class$("asp.wizard.WizardModelDbConnection")), this);
  328.                model.setSkip(true);
  329.                ((WizardModelDbConnection)model).setDefConnection(newDefConnection);
  330.                model = (WizardModelAbstract)wizman.getModelOfClassRightOf(class$asp$wizard$WizardModelDbQuery != null ? class$asp$wizard$WizardModelDbQuery : (class$asp$wizard$WizardModelDbQuery = class$("asp.wizard.WizardModelDbQuery")), this);
  331.                WizDbManager wdbm = WizDbManager.getInstance();
  332.                newDefQuery.setUsePreviousQuery(0);
  333.                model.setSkip(true);
  334.                ((WizardModelDbQuery)model).setDefQuery(newDefQuery);
  335.                model = (WizardModelAbstract)wizman.getModelOfClassRightOf(class$asp$wizard$WizardModelDbDetail != null ? class$asp$wizard$WizardModelDbDetail : (class$asp$wizard$WizardModelDbDetail = class$("asp.wizard.WizardModelDbDetail")), this);
  336.                if (model != null) {
  337.                   ((WizardModelDbDetail)model).setShowQuery(true);
  338.                }
  339.          }
  340.  
  341.       }
  342.    }
  343.  
  344.    // $FF: synthetic method
  345.    static Class class$(String class$) {
  346.       try {
  347.          return Class.forName(class$);
  348.       } catch (ClassNotFoundException forName) {
  349.          throw new NoClassDefFoundError(((Throwable)forName).getMessage());
  350.       }
  351.    }
  352. }
  353.